package dome9;

import java.util.Objects;

/**
 *   equals
 *   判断自定义类型需要重写equals方法
 *
 */
class Student {
    public String name;

//    public boolean equals(Object obj) {
//        Student student = (Student) obj;
//        if(this.name.equals(student.name)) {
//            return true;
//        }
//        return false;
//    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }
}


public class Test {

    public static void main(String[] args) {
        Student student1 = new Student();
        student1.name = "zhangsan";
        Student student2 = new Student();
        student2.name = "zhangsan";
        boolean flg = student1.equals(student2);
        System.out.println("flg = " + flg);

    }

}
